package com.hinnotek.amoeba.ui.activity.old

import android.os.Bundle
import androidx.activity.viewModels
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.bean.old.PtProjectDetailBean
import com.hinnotek.amoeba.databinding.ActivityPtProjectDetailBinding
import com.hinnotek.amoeba.dialog.CustomDialog
import com.hinnotek.amoeba.utilities.ToastUtils
import com.hinnotek.amoeba.viewmodels.AmibaCustomerViewModel
import com.lee.common.network.net.ObserverState
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class PTProjectDetailActivity : BaseActivity<ActivityPtProjectDetailBinding>() {

    private var customDialog: CustomDialog? = null

    val viewModel by viewModels<AmibaCustomerViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLeftVisible(true)
        val titleUser = intent.getStringExtra("title")
        setTitle(titleUser)

        setContentView(R.layout.activity_pt_project_detail)
    }

    override fun initVew() {

    }

    override fun setData() {
        val amibaCustomerProjectId = intent.getIntExtra("amibaCustomerProjectId", -1)
        getAmoebaCustomerProjectDetail(amibaCustomerProjectId)
    }

    /**
     * app端通过项目id查单个项目接口
     * @param amibaCustomerProjectId
     */
    private fun getAmoebaCustomerProjectDetail(amibaCustomerProjectId: Int) {
        customDialog = CustomDialog(mContext, "正在加载...")
        customDialog?.show()
        viewModel.getCustomerProjectById(amibaCustomerProjectId).observe(this, object :
            ObserverState<PtProjectDetailBean>() {
            override fun onDataChange(data: PtProjectDetailBean) {
                bindingView.tvPtCreateProject.text = data.projectName
                bindingView.tvPtProjectKeyword.text = data.projectExplain
                bindingView.tvPtTotalCost.text = data.allMoney
                bindingView.tvPtLaborCost.text = data.totalPerson
                bindingView.tvPtReimbursementCost.text = data.totalReimburse
                bindingView.tvPtPaymentCost.text = data.totalPay
                bindingView.tvPtPurchaseCost.text = data.totalPurchase
                bindingView.tvPtInstallCost.text = data.totalInstall
                bindingView.tvPtRenewalCost.text = data.totalOther
                bindingView.tvPtDevCost.text = data.totalDevelop
                super.onDataChange(data)
            }
            override fun onError(msg: String?, code: Int) {
                ToastUtils.showShort(mContext, msg)
                customDialog?.dismiss()
                super.onError(msg, code)
            }
        })
    }

}